# -*- coding: utf-8 -*-

import time
from rich.console import Console
from rich.table import Table
from rich.progress import track
from rich.text import Text


def print_fake_loading(length, interval):
    """
    hahah, just for fun
    """
    for n in track(range(length), description="Loading..."):
        time.sleep(interval)


def print_dict_as_table(table_name: str, s: dict):
    table = Table(title=table_name)

    table.add_column("Field", justify="right", style="cyan", no_wrap=True)
    table.add_column("Value", style="magenta")

    for k, v in s.items():
        table.add_row(str(k), str(v))

    console = Console()
    console.print(table)


def print_error(e: str):
    text = Text(e)
    text.stylize("bold red")
    console = Console()
    console.print(text)
